package com.dly.blog.listener;

import com.dly.blog.domain.OpLogEntity;
import com.dly.blog.event.OpLogEvent;
import com.dly.blog.inteface.LogStorageService;
import lombok.AllArgsConstructor;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 日志上传事件
 * @Author: DaiLiYu
 * @Date: 2023/7/17 11:25
 */
@Async
@AllArgsConstructor
@Component
public class OpLogEventListener implements ApplicationListener<OpLogEvent> {

    private final LogStorageService logStorageService;

    @Override
    public void onApplicationEvent(OpLogEvent event) {
        if(event.getSource() instanceof OpLogEntity opLogEntity){
            logStorageService.saveLog(opLogEntity);
        }
    }
}
